package edu.ynmd.cvs.action;

import edu.ynmd.cvs.vo.FormVo;
import edu.ynmd.cvs.vo.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@Controller //修饰符

public class PublicAction {


    @RequestMapping("getStr")  //修饰符
    @ResponseBody
    public String getStr() throws Exception{

        return "你好 spring boot";

    }


    @GetMapping("getNumber")
    @ResponseBody
    public int getNumber() throws Exception{

        return 100;
    }

    @GetMapping("getBoolean")
    @ResponseBody
    public boolean getBoolean( ) throws Exception{

        return true;
    }


    @GetMapping("getDate")
    @ResponseBody
    public Date getDate() throws Exception{
        return new Date();

    }



    @PostMapping("BMI")
    @ResponseBody
    public Result bMI(@RequestBody FormVo formVo) throws Exception{

        float sgf= Float.valueOf( formVo.getSg())  ;
        float tzf=Float.valueOf(formVo.getTz());

        float result=0.0f;
        result=tzf/(sgf*sgf);

        String resultstr="";

        if(result<18.5){
            resultstr="过轻";
        }
        else if(result>=18.5&&result<=23.9){
            resultstr="正常";
        }
        else if(result>=24&result<=27){
            resultstr="过重";
        }
        else if(result>=28&&result<=32){
            resultstr="肥胖";
        }

        else {
            resultstr="非常肥胖";
        }

        String suggest="";


        switch (resultstr){
            case "过轻":
            suggest="多吃点饭";
            break;

            case "正常":
                suggest="请继续保持";
            break;
            case "过重":
                suggest="少吃点";
                break;

            case "肥胖":
                suggest="不要吃肉";
                break;
            case "非常肥胖":
                suggest="不要吃啦";
                break;




        }


Result ro=new Result();
      ro.setResult(result);
      ro.setResultstr(resultstr);
      ro.setSugguest(suggest);



        return ro;





    }




}
